package com.guigu.servicegoods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicegoods.domain.TbStockBack;
import com.guigu.servicegoods.mapper.TbStockBackMapper;
import com.guigu.servicegoods.service.TbStockBackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@Service
public class TbStockBackServiceImpl extends ServiceImpl<TbStockBackMapper, TbStockBack> implements TbStockBackService {

    @Override
    public Result findPage(Map<String, Object> searchMap, Integer page, Integer size) {
        QueryWrapper<TbStockBack> wrapper = createExample(searchMap);
        Page<TbStockBack> pageStockBack = new Page<>(page,size);
        baseMapper.selectPage(pageStockBack,wrapper);
        return Result.ok().data("row",pageStockBack.getRecords()).data("total",pageStockBack.getTotal());
    }

    // 根据查询条件封装模块对象
    private QueryWrapper<TbStockBack> createExample(Map<String, Object> searchMap) {
        QueryWrapper<TbStockBack> wrapper = new QueryWrapper<>();
        if(searchMap!=null) {
            if(searchMap.get("orderId")!=null)
                wrapper.eq("order_id",searchMap.get("orderId"));
            if(searchMap.get("skuId")!=null && !"".equals(searchMap.get("skuId")))
                wrapper.like("sku_id",searchMap.get("skuId"));
        }
        return wrapper;
    }
}
